package com.xs.bookspoststation.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import androidx.annotation.Nullable;

public class DBHelperBook extends SQLiteOpenHelper {

    private static final String DATA_NAME = "book.db";
    private static final int VERSION = 1;

    /**
     * name: 想要建立数据库的名字
     * factory:null
     * version:版本1
     */
    public DBHelperBook(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context,DATA_NAME,null,VERSION);
    }

    /**
     * 程序运行建立数据库，只运行一次
     * @param db
     */
    @Override
    public void onCreate(SQLiteDatabase db) {
        //bookid指图书编号，bookname指图书名称，booknumber指数量,bookauthor作者，bookshow介绍
        String sql = "create table bookInfo(_id integer primary key autoincrement,bookid varchar(30),bookname varchar(30),booknumber varchar(30),bookauthor varchar(30),bookshow varchar(30))";
        db.execSQL(sql);
        Log.v("DBHelperBook","数据库及bookInfo表创建成功！");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
